const express = require('express');
const { routeWrapper } = require('../../../lib/module/tool/route');
const router = express.Router();

const CreditService = require('../../../lib/service/creditService');
const AdminService = require('../../../lib/service/adminService');

// 开通信用支付
router.post('/:areaId/opnecredit', routeWrapper(async (req) => {
    return CreditService.openCreditPayment(req.body.userId, req.body.creditAmount, req.body.isEnable);
}, true));

// 查询开通信用金用户
router.post('/credituserlist/:offset/:rows', routeWrapper(async (req) => {
    return AdminService.getCreditUserList(req.params.offset, req.params.rows, req.body);
}, true));

// 设置信用额度
router.post('/setcredit', routeWrapper(async (req) => {
    return CreditService.setCreditInfo(req.body.userId, req.body.creditAmount, req.body.isEnable);
}, true));

// 查询用户信用金使用记录
router.get('/creaditRecordList/:offset/:rows', routeWrapper(async (req) => {
    return CreditService.getUserCreditRecord(req.query.userId, req.params.offset, req.params.rows);
}, true));

// 后台偿还信用金
router.post('/payCreditRecord/:creditRecordId', routeWrapper(async (req) => {
    return CreditService.payCreditRecord(req.params.creditRecordId);
}, true));

module.exports = router;
